# 获取短信验证码
import logging

from utils.mysql_util import db


def get_code(mobile):
    sql = "select code from users_verifycode where mobile = '%s' order by id desc" % mobile
    result = db.select_db_one(sql)
    logging.info(f'sql执行结果：{result}')
    return result["code"]


def delete_user(mobile):
    sql = "delete from users_userprofile where mobile = '%s'" % mobile
    result = db.execute_db(sql)
    logging.info(f'sql执行结果：{result}')
    # return result


def delete_code(mobile):
    sql = "delete from users_verifycode where mobile = '%s'" % mobile
    result = db.execute_db(sql)
    logging.info(f'sql执行结果：{result}')
    # return result


def get_shopping_number(mobile, goods):
    user_id = get_userid(mobile)
    sql = "select nums from trade_shoppingcart where user_id='%s' and goods_id = '%s'" % (user_id, goods)
    result = db.select_db_one(sql)
    logging.info(f'sql执行结果：{result}')
    return result["nums"]


def get_userid(mobile):
    sql = "select id from users_userprofile where mobile='%s'" % mobile
    result = db.select_db_one(sql)
    logging.info(f'sql执行结果：{result}')
    return result["id"]
